package com.example.activiti.controller;

import com.example.activiti.common.core.controller.BaseController;
import com.example.activiti.common.core.domain.AjaxResult;
import com.example.activiti.common.core.page.PageDomain;
import com.example.activiti.common.core.page.TableDataInfo;
import com.example.activiti.common.core.page.TableSupport;
import com.example.activiti.domain.dto.ActTaskDTO;
import com.example.activiti.domain.dto.ActWorkflowFormDataDTO;
import com.example.activiti.service.IActTaskService;
import com.github.pagehelper.Page;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;


/**
 * @author Administrator
 */
@RestController
@RequestMapping("/task")
public class TaskController extends BaseController {

    @Resource
    private IActTaskService actTaskService;

    /**
     * 1.根据userId获取待办任务列表
     *
     * @param userId 用户唯一标识
     * @return 待办列表
     */
    @GetMapping(value = "/list")
    public TableDataInfo getTasks(@RequestParam("userId") String userId) {
        PageDomain pageDomain = TableSupport.buildPageRequest();
        Page<ActTaskDTO> hashMaps = actTaskService.selectTaskListByUserId(pageDomain, userId);
        return getDataTable(hashMaps);
    }

    /**
     * 2.根据taskId获取待办任务详情
     *
     * @param taskId 任务ID
     * @return 待办任务详情数据
     */
    @GetMapping(value = "/formDataShow/{taskId}")
    public AjaxResult formDataShow(@PathVariable("taskId") String taskId) {
        return AjaxResult.success(actTaskService.formDataShow(taskId));
    }

    /**
     * 3.根据taskId处理待办任务
     *
     * @param taskId   任务ID
     * @param formData 表单数据
     * @return 响应对象
     */
    @PostMapping(value = "/formDataSave/{taskId}")
    public AjaxResult formDataSave(@PathVariable("taskId") String taskId,
                                   String userId,
                                   @RequestBody List<ActWorkflowFormDataDTO> formData) {
        return toAjax(actTaskService.formDataSave(taskId, userId, formData));
    }

}
